//
//  DrugDetailHeaderView.m
//  MedicineBox
//
//  Created by dllo on 15/8/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "DrugDetailHeaderView.h"
#import "HomeModel.h"
#import "UIImageView+WebCache.h"
@interface DrugDetailHeaderView ()

@property (nonatomic, retain) UIImageView *picView;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *drugCompanyNameLabel;
@property (nonatomic, retain) UILabel *gongnengLabel;
@property (nonatomic, retain) UILabel *lickeLabel;
@end

@implementation DrugDetailHeaderView

- (void)dealloc
{
    [_drugCompanyNameLabel release];
    [_gongnengLabel release];
    [_name release];
    [_nameLabel release];
    [_picView release];
    [_lickeLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.picView = [[UIImageView alloc] init];
        [self addSubview:self.picView];
        [_picView release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.drugCompanyNameLabel = [[UILabel alloc] init];
        [self addSubview:self.drugCompanyNameLabel];
        [_drugCompanyNameLabel release];
        
        self.gongnengLabel = [[UILabel alloc] init];
        [self addSubview:self.gongnengLabel];
        [_gongnengLabel release];
        
        self.lickeLabel = [[UILabel alloc] init];
        [self addSubview:self.lickeLabel];
        [_lickeLabel release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.picView.frame = CGRectMake(10, 10, 100, 100);
    
    CGFloat width = self.picView.frame.size.width + self.picView.frame.origin.x;
    
    self.nameLabel.frame = CGRectMake(width + 10, 10, self.frame.size.width - width - 30, 20);
    self.nameLabel.text = self.name;
    self.nameLabel.textColor = [UIColor blackColor];

    self.drugCompanyNameLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height, self.nameLabel.frame.size.width, 20);
    self.drugCompanyNameLabel.textColor = [UIColor grayColor];
    self.drugCompanyNameLabel.font = [UIFont fontWithName:@"Marion" size:13];
    
    self.gongnengLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.drugCompanyNameLabel.frame.size.height + self.drugCompanyNameLabel.frame.origin.y, self.nameLabel.frame.size.width, 40);
    self.gongnengLabel.textColor = [UIColor grayColor];
    self.gongnengLabel.font = [UIFont fontWithName:@"Marion" size:13];
    self.gongnengLabel.numberOfLines = 2;
    
    self.lickeLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.gongnengLabel.frame.origin.y + self.gongnengLabel.frame.size.height, self.nameLabel.frame.size.width, 30);
    int value = [self.score intValue];
    for (int i = 0; i < 5; i++) {
        UIImageView *star = [[UIImageView alloc]initWithFrame:CGRectMake(i * 15, 5, 15, 15)];
        if (i < value) {
            star.image = [UIImage imageNamed:@"like.png"];
        }
        else{
            star.image = [UIImage imageNamed:@"disLike.png"];
        }
        [self.lickeLabel addSubview:star];
    }


}

- (void)valueWithModel:(HomeModel *)model
{
    [self.picView sd_setImageWithURL:[NSURL URLWithString:model.titleimg]];
    self.drugCompanyNameLabel.text = model.refdrugcompanyname;
    self.gongnengLabel.text = model.gongneng;
}






@end
